package dependence

import (
	"errorX"
	"fmt"
	"math/rand"
	"time"
)

func SaveError(e error, ctx ... map[string]interface{}) string {
	var tmpC map[string]interface{}
	if len(ctx) >= 1 {
		tmpC = ctx[0]
	} else {
		tmpC = make(map[string]interface{}, 0)
	}

	uuidNo := RandomString()

	fmt.Println(errorx.WrapContext(e, tmpC).Error())

	return uuidNo
}

func RandomString() string {
	str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
	var r *rand.Rand

	r = rand.New(rand.NewSource(time.Now().UnixNano()))

	var result string
	for i := 0; i < 32; i++ {
		result += string(str[r.Intn(len(str))])
	}
	return result
}
